#!/usr/bin/make -f
# -*- makefile-gmake -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# This has to be exported to make some magic below work.
export DH_OPTIONS

export DEB_BUILD_MAINT_OPTIONS=reproducible=-timeless

%:
	dh $@ --with gir

CMAKE_BUILD_TYPE = RelWithDebInfo

override_dh_auto_configure:
	env						\
	  PATH=/usr/lib/go-1.21/bin:$${PATH}		\
	  dh_auto_configure				\
	    --sourcedirectory=c/			\
	    --builddirectory=c.build			\
	    --buildsystem=cmake+ninja			\
	    --						\
	    -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)	\
	    -DADBC_DRIVER_FLIGHTSQL=ON			\
	    -DADBC_DRIVER_MANAGER=ON			\
	    -DADBC_DRIVER_POSTGRESQL=ON			\
	    -DADBC_DRIVER_SNOWFLAKE=ON			\
	    -DADBC_DRIVER_SQLITE=ON

override_dh_auto_build:
	dh_auto_build				\
	  --sourcedirectory=c			\
	  --builddirectory=c.build
	dh_auto_configure				\
	  --sourcedirectory=glib			\
	  --builddirectory=glib.build			\
	  --buildsystem=meson+ninja			\
	  --						\
	  --buildtype=debugoptimized			\
	  -Dadbc_build_dir=../c.build/driver_manager	\
	  -Dvapi=true
	env							\
	  LD_LIBRARY_PATH=$(CURDIR)/c.build/driver_manager	\
	    dh_auto_build					\
	      --sourcedirectory=glib				\
	      --builddirectory=glib.build			\
	      --buildsystem=meson+ninja

override_dh_auto_install:
	dh_auto_install				\
	  --sourcedirectory=c			\
	  --builddirectory=c.build
	dh_auto_install				\
	   --sourcedirectory=glib		\
	   --builddirectory=glib.build		\
	   --buildsystem=meson+ninja

override_dh_auto_test:

override_dh_dwz:
	# libadbc_driver_flightsql.so.* has compressed DWARF.
	# We can't use dwz for compressed DWARF.
	dh_dwz \
		--exclude=libadbc_driver_flightsql \
		--exclude=libadbc_driver_postgresql \
		--exclude=libadbc_driver_snowflake \
		--exclude=libadbc_driver_sqlite
